package com.mlk.core.component.permission;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * 数据权限sql格式化器
 */
public abstract class DataPermissionSqlFormat {

    /**
     * 传入源sql,然后进行格式化
     *
     * @param sourceSql
     * @return
     */
    public abstract String formatSql(String sourceSql);

    private static final Map<DataPermission, DataPermissionSqlFormat> sqlFormats = Maps.newHashMap();

    static{
        sqlFormats.put(DataPermission.PERSONAL_PERMISSON,new PersonalDataPermissionSqlFormat());
        sqlFormats.put(DataPermission.DEPT_PERMISSION,new DeptDataPermissionSqlFormat());
    }

    /**
     * 获取对应的sql格式化对象实例
     *
     * @return
     */
    public static DataPermissionSqlFormat getInstance(DataPermission dataPermission) {
        return sqlFormats.get(dataPermission.getPermission());
    }
}
